package com.corpdata.app.project.dao;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.corpdata.app.project.entity.ProjectPartition;
import com.corpdata.core.base.BaseMapper;

/**
 * 楼层分区 持久层接口
 * @author wu
 * @email 64088839@qq.com
 * @date 2018-06-08 15:23:00
 * 
 */
public interface ProjectPartitionMapper extends BaseMapper<ProjectPartition>{

	/**
	 * 根据项目id查询类型为封闭（Partition_type=2）的分区
	 * 没有合同或者合同已过期
	 * @param projectid
	 * @return
	 */
	@Select("select a.id,a.Partition_name partitionName "+
			"from project_partition a " + 
			"inner join project_building b on a.fk_project=b.id " + 
			"left join contract_partition c on c.fk_partition=a.id and flag=1 "+
			"left join contract_info d on d.id=c.fk_contract "+
			"where b.fk_project=#{projectid} and a.Partition_type=2 and (d.id is null or d.realEndDate <#{realEndDate} ) GROUP BY a.id")
	List<Map<String, Object>> selectPartitionByProject(@Param("projectid")String projectid,@Param("realEndDate")Date realEndDate);
}
